package com.chat.admin.controller;

import com.chat.admin.annotate.IsNumeric;
import com.chat.admin.domain.DTO.ADD.AddUserDTO;
import com.chat.admin.domain.DTO.DisableAccountDTO;
import com.chat.admin.domain.DTO.EDIT.EditUserDTO;
import com.chat.admin.domain.DTO.UserAppealDTO;
import com.chat.admin.domain.DTO.UserDTO;
import com.chat.admin.domain.DTO.UserFeedbackDTO;
import com.chat.admin.domain.VO.UserAppealVO;
import com.chat.admin.domain.VO.UserFeedbackVO;
import com.chat.admin.domain.VO.UserVO;
import com.chat.admin.service.UserManagementService;
import com.chat.common.form.ListForm;
import com.chat.common.vo.R;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 管理员操作用户信息模块
 */
@RestController
@Validated
@RequestMapping("/admin/user")
public class UserManagementController {

    @Autowired
    UserManagementService userManagementService;

    /**
     * 获取用户列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getUserList")
    public R<ListForm<UserVO>> getUserList(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "20") Integer size) {
        return userManagementService.getUserList(page,size);
    }

    /**
     * 条件获取用户列表
     * @param userDTO
     * @return
     */
    @PostMapping("/getUserList")
    public R<ListForm<UserVO>> getUserList(@RequestBody UserDTO userDTO) {
        return userManagementService.getUserList(userDTO);
    }

    /**
     * 修改用户信息
     * @param editUserDTO
     * @return
     */
    @PostMapping("/editUserInfo")
    public R<UserVO> EditUserInfo(@RequestBody EditUserDTO editUserDTO) {
        return userManagementService.EditUserInfo(editUserDTO);
    }

    /**
     * 禁用账号
     * @param
     * @return
     */
    @PostMapping("/disableAccount")
    public R<?> DisableAccount(@RequestBody DisableAccountDTO disableAccountDTO) {
        return userManagementService.DisableAccount(disableAccountDTO);
    }

    /**
     * 启用账号
     * @param userID
     * @return
     */
    @GetMapping("/enableAccount")
    public R<?> EnableAccount(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "userID不是数字") String userID){
        return userManagementService.EnableAccount(Long.valueOf(userID));
    }

    /**
     * 添加一个用户账号
     * @param addUserDTO
     * @return
     */
    @PostMapping("/addOneUserAccount")
    public R<?> addOneUserAccount(@RequestBody @Validated AddUserDTO addUserDTO){
        return userManagementService.addOneUserAccount(addUserDTO);
    }

    /**
     * Excel批量添加账户
     * @param file
     * @return
     */
    @PostMapping("/addExcelUserAccount")
    public R<?> addExcelUserAccount(MultipartFile file) {
        return userManagementService.addExcelUserAccount(file);
    }

    /**
     * 获取用户申述列表
     * @param userAppealDTO
     * @return
     */
    @PostMapping("/getUserApplication")
    public R<ListForm<UserAppealVO>> getUserApplication(@RequestBody UserAppealDTO userAppealDTO){
        return userManagementService.getUserApplication(userAppealDTO);
    }

    /**
     * 同意用户申请
     * @param applyID
     * @return
     */
    @GetMapping("/agreeUserApplication")
    public R agreeUserApplication(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "applyID不是数字") String applyID){
        return userManagementService.agreeUserApplication(applyID);
    }

    /**
     * 拒绝用户申请
     * @param applyID
     * @return
     */
    @GetMapping("/refuseUserApplication")
    public R refuseUserApplication(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "applyID不是数字") String applyID){
        return userManagementService.refuseUserApplication(applyID);
    }

    @PostMapping("/getUseFeedback")
    public R<ListForm<UserFeedbackVO>> getUserFeedback(@RequestBody UserFeedbackDTO userFeedbackDTO){
        return userManagementService.getUserFeedback(userFeedbackDTO);
    }

    @GetMapping("/handleUserFeedback")
    public R HandleUserFeedback(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "ID不是数字") String ID){
        return userManagementService.HandleUserFeedback(ID);
    }

}
